#include "uri.h"
#include "progress.h"

void show_progress(URI *uri) {

   int show=((PROGRESS_COLUMN*uri->progress++)/100),i;

   printf("\r{");
   for(i=0;i<PROGRESS_COLUMN;i++) {

      if(i<=show)
         printf("=");
      else
         printf(" ");

   }
   printf("} [ %.*d%% ] %.*f Kb/s", 2, uri->progress, 0, uri->bps  );


   fflush(stdout);

}

void * update_progress(void *arg) {

    URI *uri;
    long int bytes_last;

    uri = (URI *) arg;

    while(1) {

       bytes_last = uri->bytes;
       sleep(1);
       uri->bps = (float) (uri->bytes - bytes_last);

    }

}
